 <template>
    <div>
        <div class="e-form">
            <BillTop  @cancel="handleClose"></BillTop>
            <div class="tabs" style="margin-bottom: 120px">
                <div class="tabs-title">基本信息</div>
                <div style="width: 100%" class="form">
                    <el-form  :model="basicForm" :label-width="formLabelWidth"
                    ref="ruleForm"
                     :rules="rules"
                     class="demo-ruleForm">
                        <el-row>

                            <el-col :span="12">
                               <el-form-item label="所属机构：">
                                    <span>{{ basicForm.orgName }}</span>
                                </el-form-item>
                            </el-col>

                        </el-row>
                               <el-row>
                            <el-col :span="12">
                                <el-form-item label="接收人员：">
                                                                       <span>
                                      {{
                                          basicForm.receiverName
                                      }}
                                  </span>

                                </el-form-item>
                            </el-col>
                              <el-col :span="12">
                                  <el-form-item  label="退货日期：" prop="returnedDate">
                                    <el-date-picker
                                        value-format="yyyy-MM-dd"
                                        :clearable="false"
                                        type="date"
                                        placeholder="选择日期"
                                        v-model="basicForm.returnedDate"
                                    ></el-date-picker>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                 <el-form-item label="接收数量：">
                                   <span>

                                       {{basicForm.receiptQuantity}}
                                   </span>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">

                                     <el-form-item label="库管人员：">
                                    <el-input v-model="basicForm.treasurerName" readonly>

                                        <i slot="suffix" class="el-input__icon el-icon-document-copy" @click="selectName"></i>
                                  </el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>

                         <el-row>
                            <el-col :span="12">
                                <el-form-item label="截止上期退货数量：">
                                    <span>{{ basicForm.prevTotalReturnedQuantity }}</span>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="状态：">
                                    <span>{{
                                       stateArr[basicForm.state]
                                    }}</span>
                                </el-form-item>
                            </el-col>
                        </el-row>
                         <el-row>
                            <el-col :span="12">
                                <el-form-item label="截止本期退货数量：">
                                    <span>{{ basicForm.currTotalReturnedQuantity }}</span>
                                </el-form-item>
                            </el-col>
                            <!-- <el-col :span="12">
                                <el-form-item label="评价等级：">
                                        <el-input v-model="basicForm.evaluationGrade"></el-input>
                                        <el-button
                                           type="primary"
                                    size="small"
                                    style="background: #2e61d7"
                                        >退库评价</el-button>
                                </el-form-item>
                            </el-col> -->
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="备注：">
                                    <el-input
                                        type="textarea"
                                        v-model="basicForm.remarks"
                                        autocomplete="off"
                                    ></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>

                    </el-form>
                </div>
            </div>
            <div class="buttons">
                       <span class="tip"><span style="color: red; margin-right: 0">*</span>为必填项</span>
                <el-button
                    type="primary"
                    size="small"
                    style="background: #2e61d7"
                    @click="addSave"
                    >保存</el-button
                >
                <el-button size="small" @click="handleClose">取消</el-button>
            </div>
        </div>
    </div>
</template>

<script>
// import { selectDataClient, openAppClient } from '@/utils/common'
import { mapMutations } from 'vuex'
import { selectgetUserUnderOrgPage } from '@/api/turnover/ppw.js'

export default {
    data () {
        return {
            //基础信息
            basicForm: {
                'billId': '',
                'billNo': '',
                'currReturnedQuantity': 0,
                'currTotalReturnedQuantity': 0,
                'dtlList': [],
                'evaluationGrade': '',
                'nullifyCreated': '',
                'nullifyCreator': '',
                'nullifyCreatorId': '',
                'nullifyDescription': '',
                'nullifyReason': '',
                'orgId': '',
                'orgName': '',
                'prevTotalReturnedQuantity': 0,
                'receiptQuantity': 0,
                'receiverId': '',
                'receiverName': '',
                'remarks': '',
                'returnedDate': new Date,
                'state': 0,
                'supplierId': '',
                'supplierName': '',
                'treasurerId': '',
                'treasurerName': ''
            },
            formLabelWidth: '180px',
            currencyArr: [], //币种列表
            stateArr: ['草稿', '审核中', '已审核', '已作废'],
            rules: {
                returnedDate: [
                    { required: true, message: '请选择业务类型' },
                ],
            },
        }
    },
    created () {
        this.getUserInfo()
    },

    methods: {
        ...mapMutations(['setSelectedInfo']),

        //获取本地登录信息
        getUserInfo () {
            const userInfo = JSON.parse(window.localStorage.getItem('vuex')).userInfo.orgInfo
            const userName = window.localStorage.getItem('userName')
            const userId = window.localStorage.getItem('userId')
            this.basicForm.receiverName = userName
            this.basicForm.receiverId = userId
            this.basicForm.treasurerName = userName
            this.basicForm.treasurerId = userId

            this.basicForm.orgId = userInfo.orgId
            this.basicForm.orgName = userInfo.orgName
        },
        //基本信息保存
        addSave () {
            this.$Ajax
                .httpPost({
                    url: '/turnover/providerReturnedPurchase/create',
                    params: this.basicForm
                })
                .then(res => {
                    this.clientPop('info', '保存成功!是否进行下一步操作？', ()=>{
                        this.$router.push({
                            path: '/revolveSalesReturnEdit',
                            query: {
                                billid: res,
                                name: 'detailed'
                            }
                        })
                    },
                    null,
                    this.handleClose
                    )
                })
        },
        selectName () {
            selectgetUserUnderOrgPage(this.basicForm.orgId).then(res=>{
                this.basicForm.treasurerName = res.userName
                this.basicForm.treasurerId = res.userId
            })
        },
        //取消
        handleClose () {
            this.$router.push('/revolveSalesReturnList')
        }
    }
}
</script>

<style lang="scss" scoped>
.buttons {
    left: 0;
}
.e-form {
    padding: 0 20px;
    .tabs-title::before {
        content: '';
        height: 22px;
        width: 8px;
        border-radius: 40px;
        background-color: #2e61d7;
        display: block;
        position: absolute;
        left: 20px;
        margin-right: 20px;
    }
}
.e-table {
    min-height: auto;
    background: #fff;
}
.separ {
    width: 30px;
    height: 40px;
    line-height: 18px;
    text-align: center;
}
.upload {
    margin: 20px auto;
    display: flex;
    justify-content: center;
    text-align: center;
}

.upload-demo {
    display: flex;
    justify-content: center;
    align-items: center;
}

::v-deep.el-input--suffix .el-input__inner {
    padding-right: 5px;
}
::v-deep.el-table .cell {
    text-align: center;
}
</style>
